<template>
  <div class="cleaner-management">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>保洁人员管理</span>
          <el-button type="primary" @click="handleAdd">新增保洁员</el-button>
        </div>
      </template>
      
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="关键词">
          <el-input v-model="searchForm.keyword" placeholder="姓名/员工编号" />
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="searchForm.status" placeholder="全部">
            <el-option label="全部" value="" />
            <el-option label="在岗" :value="1" />
            <el-option label="休息" :value="2" />
            <el-option label="离职" :value="3" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">搜索</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
      
      <el-table :data="cleanerList" style="width: 100%" v-loading="loading">
        <el-table-column prop="employeeNo" label="员工编号" />
        <el-table-column prop="realName" label="姓名" />
        <el-table-column prop="phone" label="联系电话" />
        <el-table-column prop="skillLevel" label="技能等级">
          <template #default="{ row }">
            <el-rate v-model="row.skillLevel" disabled />
          </template>
        </el-table-column>
        <el-table-column prop="workExperience" label="工作经验">
          <template #default="{ row }">
            {{ row.workExperience }}年
          </template>
        </el-table-column>
        <el-table-column prop="currentStatus" label="当前状态">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.currentStatus)">
              {{ getStatusLabel(row.currentStatus) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button size="small" @click="handleEdit(row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <el-pagination
        v-model:current-page="pagination.page"
        v-model:page-size="pagination.size"
        :total="pagination.total"
        @current-change="handlePageChange"
        layout="total, prev, pager, next"
      />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'

const loading = ref(false)
const cleanerList = ref([])
const searchForm = reactive({
  keyword: '',
  status: ''
})
const pagination = reactive({
  page: 1,
  size: 10,
  total: 0
})

const getStatusLabel = (status: number) => {
  const labels = {
    1: '在岗',
    2: '休息',
    3: '离职'
  }
  return labels[status] || '未知'
}

const getStatusType = (status: number) => {
  const types = {
    1: 'success',
    2: 'warning',
    3: 'danger'
  }
  return types[status] || 'info'
}

const loadCleaners = () => {
  loading.value = true
  // 模拟数据
  cleanerList.value = [
    {
      id: 1,
      employeeNo: 'C001',
      realName: '王师傅',
      phone: '13800138001',
      skillLevel: 4,
      workExperience: 5,
      currentStatus: 1
    },
    {
      id: 2,
      employeeNo: 'C002',
      realName: '李阿姨',
      phone: '13800138002',
      skillLevel: 3,
      workExperience: 3,
      currentStatus: 1
    }
  ]
  pagination.total = 2
  loading.value = false
}

const handleSearch = () => {
  pagination.page = 1
  loadCleaners()
}

const handleReset = () => {
  searchForm.keyword = ''
  searchForm.status = ''
  handleSearch()
}

const handlePageChange = (page: number) => {
  pagination.page = page
  loadCleaners()
}

const handleAdd = () => {
  console.log('新增保洁员')
}

const handleEdit = (row: any) => {
  console.log('编辑保洁员', row)
}

const handleDelete = (row: any) => {
  console.log('删除保洁员', row)
}

onMounted(() => {
  loadCleaners()
})
</script>

<style scoped>
.cleaner-management {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-form {
  margin-bottom: 20px;
}
</style>